<template>
  <div class="app-container">
    <div class="table-btn">
      <el-dialog
        :title="dialogTitle"
        :show-close="false"
        width="440px"
        style="margin-top: 300px"
        :fullscreen="true"
        :modal="false"
        :close-on-click-modal="false"
        :visible.sync="outerVisible"
        :append-to-body="appendbody"
        :modal-append-to-body="false"
      >
        <el-form ref="teamRow" :rules="rules" :model="teamRow" label-width="100px">
          <el-form-item prop="oldPassword" label="旧密码" size="small">
            <el-input type="password" v-model="teamRow.oldPassword"></el-input>
          </el-form-item>
          <el-form-item prop="newPassword" label="新密码" size="small">
            <el-input type="password" v-model="teamRow.newPassword"></el-input>
          </el-form-item>
          <el-form-item prop="ispassword" label="确认密码" size="small">
            <el-input type="password" v-model="teamRow.ispassword"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="warning" size="small"  @click="submitForm('teamRow')" v-no-more-click>确定</el-button>
          <el-button size="small" @click="routerto()">取消</el-button>
        </div>
      </el-dialog>
      <!--<el-button size="small" icon="el-icon-upload2">导出</el-button>-->
    </div>
  </div>
</template>

<script>
  import { update } from '@/api/updatepassword'
  import myTable from '@/components/myTable'

  import { AreaSelect } from 'vue-area-linkage'
  import { pca } from 'area-data'

  export default {
    components: {
      myTable,
      AreaSelect
    },
    data() {
      return {
        appendbody: true,
        listLoading: true,
        dialogTitle: '修改密码',
        dialogType: 0,
        teamRow: {},
        outerVisible: true,
        pca: pca,
        message: '',
        rules: {},
        visible: false
      }
    },
    created() {
    },
    methods: {
      routerto() {
        this.$store.dispatch('LogOut').then(() => {
          location.reload() // 为了重新实例化vue-router对象 避免bug
        })
      },
      submitForm(formName) {
        if (this.teamRow.newPassword === this.teamRow.ispassword) {
          const params = {
            oldPassword: this.teamRow.oldPassword,
            newPassword: this.teamRow.newPassword
          }
          this.$refs[formName].validate((valid) => {
            if (valid) {
              update(params).then(response => {
                if (response.resultCode === 2) {
                  setTimeout(this.routerto, 500)
                }
              })
            } else {
              console.log('error submit!!')
              return false
            }
          })
        } else {
          this.$message({
            message: '密码输入不一致',
            type: 'warning'
          })
        }
      }
    },
    mounted() {
      console.log(this.pca)
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .el-dialog__wrapper {
    width: 440px;
    margin: auto;
  }

  .app-container {
    .el-pagination {
      margin-top: 20px;
    }
    .table-btn {
      margin-bottom: 10px;
      & > button {
        margin: 0 20px;
      }
      .el-dialog {
        textarea {
          margin-top: 10px;
        }
        .el-checkbox {
          margin-right: 20px;
        }
        .el-checkbox + .el-checkbox {
          margin-left: 0;
        }
      }
    }
  }

</style>


<style rel="stylesheet/scss" lang="scss">
  .el-input__icon {
    line-height: 100%;
  }

  .el-form-item__content {
    line-height: 33px;
  }

  .area-select .area-selected-trigger {
    padding: 0 10px;
  }

  /*.el-table__body tr.hover-row>td {
    background-color: #0000ff !important;
  }

  .el-table__body tr.current-row>td {
    background-color: #0000ff !important;
  }*/
</style>
